/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsAccountReceiveMoneyDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsAccountReceiveMoneyDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsAccountReceiveMoneyDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsAccountReceiveMoneyDO objcmsAccountReceiveMoneyDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@OrderCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.OrderCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromAccount", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.FromAccount;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToAccount", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ToAccount;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromCustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.FromCustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToCustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ToCustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderValue", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.OrderValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ReceivedValue", SqlDbType.BigInt);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ReceivedValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ReceivedPercent", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ReceivedPercent;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Status", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.Status;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UserId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.UserId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsAccountReceiveMoneyDO objcmsAccountReceiveMoneyDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.OrderCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromAccount", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.FromAccount;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToAccount", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ToAccount;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromCustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.FromCustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToCustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ToCustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderValue", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.OrderValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ReceivedValue", SqlDbType.BigInt);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ReceivedValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ReceivedPercent", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ReceivedPercent;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Status", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.Status;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UserId", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.UserId;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }
        public DataTable Search(string type, DateTime searchDate, DateTime fromDate, DateTime toDate, string status,int customerId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsAccountReceiveMoney_Search";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Type", SqlDbType.NVarChar);
            Sqlparam.Value = type;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SearchDate", SqlDbType.DateTime);
            Sqlparam.Value = searchDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromDate", SqlDbType.DateTime);
            Sqlparam.Value = fromDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToDate", SqlDbType.DateTime);
            Sqlparam.Value = toDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Status", SqlDbType.NVarChar);
            Sqlparam.Value = status;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = customerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable Statistic(DateTime fromDate, DateTime toDate, int customerId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_Statistic";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@FromDate", SqlDbType.DateTime);
            Sqlparam.Value = fromDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToDate", SqlDbType.DateTime);
            Sqlparam.Value = toDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CustomerId", SqlDbType.Int);
            Sqlparam.Value = customerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public int Delete(cmsAccountReceiveMoneyDO objcmsAccountReceiveMoneyDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsAccountReceiveMoneyDO Select(cmsAccountReceiveMoneyDO objcmsAccountReceiveMoneyDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Value = objcmsAccountReceiveMoneyDO.ID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objcmsAccountReceiveMoneyDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["OrderCode"]))
                    objcmsAccountReceiveMoneyDO.OrderCode = Convert.ToString(dr["OrderCode"]);
                if (!Convert.IsDBNull(dr["FromAccount"]))
                    objcmsAccountReceiveMoneyDO.FromAccount = Convert.ToString(dr["FromAccount"]);
                if (!Convert.IsDBNull(dr["ToAccount"]))
                    objcmsAccountReceiveMoneyDO.ToAccount = Convert.ToString(dr["ToAccount"]);
                if (!Convert.IsDBNull(dr["FromCustomerId"]))
                    objcmsAccountReceiveMoneyDO.FromCustomerId = Convert.ToInt32(dr["FromCustomerId"]);
                if (!Convert.IsDBNull(dr["ToCustomerId"]))
                    objcmsAccountReceiveMoneyDO.ToCustomerId = Convert.ToInt32(dr["ToCustomerId"]);
                if (!Convert.IsDBNull(dr["OrderValue"]))
                    objcmsAccountReceiveMoneyDO.OrderValue = Convert.ToInt64(dr["OrderValue"]);
                if (!Convert.IsDBNull(dr["ReceivedValue"]))
                    objcmsAccountReceiveMoneyDO.ReceivedValue = Convert.ToInt64(dr["ReceivedValue"]);
                if (!Convert.IsDBNull(dr["ReceivedPercent"]))
                    objcmsAccountReceiveMoneyDO.ReceivedPercent = Convert.ToInt32(dr["ReceivedPercent"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsAccountReceiveMoneyDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["Status"]))
                    objcmsAccountReceiveMoneyDO.Status = Convert.ToString(dr["Status"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsAccountReceiveMoneyDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["UserId"]))
                    objcmsAccountReceiveMoneyDO.UserId = Convert.ToInt32(dr["UserId"]);

            }
            return objcmsAccountReceiveMoneyDO;
        }
        public cmsAccountReceiveMoneyDO SelectByOrder(string orderCode)
        {
            cmsAccountReceiveMoneyDO objcmsAccountReceiveMoneyDO = new cmsAccountReceiveMoneyDO();

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_GetByOrder";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@OrderCode", SqlDbType.NVarChar);
            Sqlparam.Value = orderCode;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ID"]))
                    objcmsAccountReceiveMoneyDO.ID = Convert.ToInt32(dr["ID"]);
                if (!Convert.IsDBNull(dr["OrderCode"]))
                    objcmsAccountReceiveMoneyDO.OrderCode = Convert.ToString(dr["OrderCode"]);
                if (!Convert.IsDBNull(dr["FromAccount"]))
                    objcmsAccountReceiveMoneyDO.FromAccount = Convert.ToString(dr["FromAccount"]);
                if (!Convert.IsDBNull(dr["ToAccount"]))
                    objcmsAccountReceiveMoneyDO.ToAccount = Convert.ToString(dr["ToAccount"]);
                if (!Convert.IsDBNull(dr["FromCustomerId"]))
                    objcmsAccountReceiveMoneyDO.FromCustomerId = Convert.ToInt32(dr["FromCustomerId"]);
                if (!Convert.IsDBNull(dr["ToCustomerId"]))
                    objcmsAccountReceiveMoneyDO.ToCustomerId = Convert.ToInt32(dr["ToCustomerId"]);
                if (!Convert.IsDBNull(dr["OrderValue"]))
                    objcmsAccountReceiveMoneyDO.OrderValue = Convert.ToInt64(dr["OrderValue"]);
                if (!Convert.IsDBNull(dr["ReceivedValue"]))
                    objcmsAccountReceiveMoneyDO.ReceivedValue = Convert.ToInt64(dr["ReceivedValue"]);
                if (!Convert.IsDBNull(dr["ReceivedPercent"]))
                    objcmsAccountReceiveMoneyDO.ReceivedPercent = Convert.ToInt32(dr["ReceivedPercent"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsAccountReceiveMoneyDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["Status"]))
                    objcmsAccountReceiveMoneyDO.Status = Convert.ToString(dr["Status"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsAccountReceiveMoneyDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["UserId"]))
                    objcmsAccountReceiveMoneyDO.UserId = Convert.ToInt32(dr["UserId"]);

            }
            return objcmsAccountReceiveMoneyDO;
        }
        
        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsAccountReceiveMoneyDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsAccountReceiveMoneyDO objcmsAccountReceiveMoneyDO = new cmsAccountReceiveMoneyDO();
                    if (!Convert.IsDBNull(dr["ID"]))
                        objcmsAccountReceiveMoneyDO.ID = Convert.ToInt32(dr["ID"]);
                    if (!Convert.IsDBNull(dr["OrderCode"]))
                        objcmsAccountReceiveMoneyDO.OrderCode = Convert.ToString(dr["OrderCode"]);
                    if (!Convert.IsDBNull(dr["FromAccount"]))
                        objcmsAccountReceiveMoneyDO.FromAccount = Convert.ToString(dr["FromAccount"]);
                    if (!Convert.IsDBNull(dr["ToAccount"]))
                        objcmsAccountReceiveMoneyDO.ToAccount = Convert.ToString(dr["ToAccount"]);
                    if (!Convert.IsDBNull(dr["FromCustomerId"]))
                        objcmsAccountReceiveMoneyDO.FromCustomerId = Convert.ToInt32(dr["FromCustomerId"]);
                    if (!Convert.IsDBNull(dr["ToCustomerId"]))
                        objcmsAccountReceiveMoneyDO.ToCustomerId = Convert.ToInt32(dr["ToCustomerId"]);
                    if (!Convert.IsDBNull(dr["OrderValue"]))
                        objcmsAccountReceiveMoneyDO.OrderValue = Convert.ToInt64(dr["OrderValue"]);
                    if (!Convert.IsDBNull(dr["ReceivedValue"]))
                        objcmsAccountReceiveMoneyDO.ReceivedValue = Convert.ToInt64(dr["ReceivedValue"]);
                    if (!Convert.IsDBNull(dr["ReceivedPercent"]))
                        objcmsAccountReceiveMoneyDO.ReceivedPercent = Convert.ToInt32(dr["ReceivedPercent"]);
                    if (!Convert.IsDBNull(dr["CreatedDate"]))
                        objcmsAccountReceiveMoneyDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                    if (!Convert.IsDBNull(dr["Status"]))
                        objcmsAccountReceiveMoneyDO.Status = Convert.ToString(dr["Status"]);
                    if (!Convert.IsDBNull(dr["Note"]))
                        objcmsAccountReceiveMoneyDO.Note = Convert.ToString(dr["Note"]);
                    if (!Convert.IsDBNull(dr["UserId"]))
                        objcmsAccountReceiveMoneyDO.UserId = Convert.ToInt32(dr["UserId"]);
                    arrcmsAccountReceiveMoneyDO.Add(objcmsAccountReceiveMoneyDO);
                }
            }
            return arrcmsAccountReceiveMoneyDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsAccountReceiveMoney_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
